﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Display.ValentineUI.*;
    import Classes.orders.*;
    import Classes.orders.Valentines2011.*;

    public class ValentineManager {

        private static var m_valentines:Array;
        private static var m_admirers:Array;
        public static var m_shownIneligible:Boolean = false;

        public static function getNewValentines():Array{
            var _local2:ValentineOrder;
            ValentineManager.initValentineOrders();
            var _local1:Array = new Array();
            for each (_local2 in ValentineManager.m_valentines) {
                _local1 = _local1.concat(_local2.getNewCards());
            };
            return (_local1);
        }
        private static function initValentineOrders():void{
            if ((((ValentineManager.m_valentines == null)) || ((ValentineManager.m_valentines.length == 0)))){
                ValentineManager.m_valentines = Global.world.orderMgr.getOrdersByType(OrderType.VALENTINE_2011);
            };
        }
        private static function initAdmirers():void{
            var _local1:ValentineOrder;
            var _local2:Player;
            var _local3:Admirer;
            ValentineManager.initValentineOrders();
            if ((((ValentineManager.m_admirers == null)) || ((ValentineManager.m_admirers.length == 0)))){
                ValentineManager.m_admirers = new Array();
                for each (_local1 in ValentineManager.m_valentines) {
                    _local2 = Global.player.findFriendById(_local1.getSenderID());
                    if (_local2 != null){
                        _local3 = new Admirer(_local2.snUser.firstName, _local2.snUser.picture, _local1.getCardCount(), _local1.hasNewCards(), _local2.snUser.uid);
                        ValentineManager.m_admirers.push(_local3);
                    };
                };
            };
        }
        public static function getValentinesFromUID(_arg1:String):Array{
            var _local2:ValentineOrder = Global.world.orderMgr.getOrdersByUID(_arg1, OrderType.VALENTINE_2011, OrderStatus.RECEIVED)[0];
            return (_local2.getAllCards());
        }
        public static function getValentineCountFromUID(_arg1:String):int{
            var _local2:ValentineOrder = Global.world.orderMgr.getOrdersByUID(_arg1, OrderType.VALENTINE_2011, OrderStatus.RECEIVED)[0];
            return (_local2.getCardCount());
        }
        public static function getTotalAdmirers():int{
            ValentineManager.initValentineOrders();
            return (ValentineManager.m_valentines.length);
        }
        public static function checkUIDForNewCards(_arg1:String):Boolean{
            var _local2:ValentineOrder = Global.world.orderMgr.getOrdersByUID(_arg1, OrderType.VALENTINE_2011, OrderStatus.RECEIVED)[0];
            return (_local2.hasNewCards());
        }
        public static function getAdmirers():Array{
            ValentineManager.initAdmirers();
            return (ValentineManager.m_admirers);
        }
        public static function getAdmirerByID(_arg1:String):Admirer{
            var _local2:Admirer;
            ValentineManager.initAdmirers();
            for each (_local2 in ValentineManager.m_admirers) {
                if (_local2.uid == _arg1){
                    return (_local2);
                };
            };
            return (null);
        }
        public static function sendValentineCard(_arg1:int, _arg2:int, _arg3:int, _arg4:String):void{
            FrameManager.navigateTo(((((((("valentine.php?lID=" + _arg1) + "&mID=") + _arg2) + "&rID=") + _arg3) + "&msg=") + escape(_arg4)));
        }
        public static function getTotalCards():int{
            var _local2:Admirer;
            ValentineManager.initAdmirers();
            var _local1:int;
            for each (_local2 in ValentineManager.m_admirers) {
                _local1 = (_local1 + _local2.numCards);
            };
            return (_local1);
        }
        public static function markCardsAsSeen(_arg1:String, _arg2:Array):void{
            var _local4:ValentineCard;
            var _local3:Array = new Array();
            for each (_local4 in _arg2) {
                _local4.setSeen();
                _local3.push(_local4.id);
            };
            GameTransactionManager.addTransaction(new TValentineMarkRead(_arg1, _local3));
        }
        public static function markAllAsSeen(_arg1:String):void{
            var _local2:Admirer;
            var _local3:Array;
            var _local4:Array;
            var _local5:ValentineCard;
            for each (_local2 in ValentineManager.m_admirers) {
                if (_local2.uid == _arg1){
                    _local2.newCard = false;
                    _local3 = ValentineManager.getValentinesFromUID(_arg1);
                    _local4 = new Array();
                    for each (_local5 in _local3) {
                        _local5.setSeen();
                        if (_local5.id.charAt(0) != "i"){
                            _local4.push(("i" + _local5.id));
                        };
                    };
                    GameTransactionManager.addTransaction(new TValentineMarkRead(_arg1, _local4));
                    break;
                };
            };
        }
        public static function checkEligibility():Boolean{
            if (Global.player.level < Global.gameSettings.getNumber("vDayMinEligibleLevel", 5)){
                return (false);
            };
            return (true);
        }
        public static function removeValentineCard(_arg1:String, _arg2:String):void{
            var _local3:ValentineOrder = Global.world.orderMgr.getOrdersByUID(_arg1, OrderType.VALENTINE_2011, OrderStatus.RECEIVED)[0];
            var _local4:Boolean = _local3.deleteCard(_arg2);
            if (_local4 == true){
                if (_local3.getCardCount() <= 0){
                    Global.world.orderMgr.removeOrder(_local3);
                } else {
                    Global.world.orderMgr.updateOrder(_local3);
                };
                ValentineManager.m_valentines = null;
                ValentineManager.m_admirers = null;
            };
        }

    }
}//package Classes.sim 
